#!/bin/bash
Usage(){
	echo "`basename $0` <account_dir> <base number> <content_dir> [max progress iber]"
	exit 1
}

if [ $# -lt 3 ]
then
	Usage
fi

ACCOUNT_DIR=$1
BASE_NUMBER=$2
CONTENT_DIR=$3
MAX_PROGRESS_NUM=$4

if [ ! -d $CONTENT_DIR ]
then
	Usage
fi

if [ ! -d $ACCOUNT_DIR ]
then
	Usage
fi

if [ "x"$MAX_PROGRESS_NUM = "x" ]
then
	MAX_PROGRESS_NUM=10
fi

LOG_DIR=`pwd`"/log/"`date +%Y-%m-%d_%H:%M:%S`
mkdir -p $LOG_DIR
i=0
while [ $i -lt $MAX_PROGRESS_NUM ]
do
	FILE_NUMBER=$((i+BASE_NUMBER))
	ACCOUNT_FILE_NAME=`printf "%s/x%02d" $ACCOUNT_DIR $FILE_NUMBER`
	LOG_FILE="$LOG_DIR/send_$FILE_NUMBER.log"
	./send_email $CONTENT_DIR $ACCOUNT_FILE_NAME >$LOG_FILE 2>&1 &
	echo "./send_email $CONTENT_DIR $ACCOUNT_FILE_NAME >$LOG_FILE 2>&1 &"
	i=$((i+1))
done
